//
// Created by Deng on 2021/8/15.
//

#include "Student.h"
#include "Teacher.h"

/**
 * 演示信号和槽。
 * QObject 指定了Parent， 析构parent时，child也会析构
 * @return
 */
int main_demo(){
    Teacher* teacher = new Teacher();
    Student* student = new Student(teacher); //指定Parent
    //连接信号和槽
    QObject::connect(teacher, SIGNAL(teach(QString)), student, SLOT(receive(QString)));
    //发信号，槽函数会被调用
    emit teacher->teach(QString("你好"));
    //delete student;
    delete teacher; //指定了teacher为student的parent,删除teacher时，student也会被析构
    return 0;
}